package com.gd.iot.energy.controller.superadmin;

import com.gd.iot.energy.annotation.SystemLogRecordMonitor;
import com.gd.iot.energy.entity.ResponseEntity;
import com.gd.iot.energy.pojo.common.vo.PageVO;
import com.gd.iot.energy.pojo.superadmin.dto.AdminSaveDTO;
import com.gd.iot.energy.pojo.superadmin.dto.PermissionSaveDTO;
import com.gd.iot.energy.pojo.superadmin.vo.PermissionVO;
import com.gd.iot.energy.service.superadmin.PermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 超级管理-用户管理-目录、菜单、权限管理
 *
 * @author kris
 * @date Created at 2020/8/3 10:50
 */
@Api(value = "超级管理-用户管理-目录、菜单、权限管理",tags = "超级管理-用户管理-目录、菜单、权限管理")
@RestController
@RequestMapping("/admin/permission")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @ApiOperation("获取目录、菜单、权限列表")
    @SystemLogRecordMonitor("获取目录、菜单、权限列表")
    @PostMapping("/getList")
    public ResponseEntity<PageVO<PermissionVO>> getList() {

        PageVO<PermissionVO> permissionVOs = permissionService.getPermissionVOs();
        return new ResponseEntity<>(permissionVOs);
    }

    @ApiOperation("获取当前用户拥有的目录、菜单、权限列表")
    @SystemLogRecordMonitor("获取当前用户拥有的目录、菜单、权限列表")
    @PostMapping("/getCurrentUserList")
    public ResponseEntity<List<PermissionVO>> getCurrentUserList() {

        List<PermissionVO> permissionVOs = permissionService.getCurrentUserPermissionVOs();
        return new ResponseEntity<>(permissionVOs);
    }


    @ApiOperation("新增目录、菜单、权限")
    @SystemLogRecordMonitor("新增目录、菜单、权限")
    @PostMapping("/add")
    public ResponseEntity<Integer> add(@RequestBody PermissionSaveDTO permissionSaveDTO){
        Integer id = permissionService.add(permissionSaveDTO);
        return new ResponseEntity<>(id);
    }

    @ApiOperation("更新目录、菜单、权限，只能修改基本信息，不能修改父级和类型")
    @SystemLogRecordMonitor("更新目录、菜单、权限")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody PermissionSaveDTO permissionSaveDTO){
        boolean res = permissionService.updatePermission(permissionSaveDTO);
        return new ResponseEntity<>(res);
    }

    @ApiOperation("删除目录、菜单、权限")
    @SystemLogRecordMonitor("删除目录、菜单、权限")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody List<Integer> ids){
        boolean res = permissionService.delete(ids);
        return new ResponseEntity<>(res);
    }
}
